﻿using GalaSoft.MvvmLight;
using KinectCurve.ViewModel;

namespace KinectCurve
{
    public class ViewModelLocator
    {
        public ViewModelLocator()
        {
            if (ViewModelBase.IsInDesignModeStatic)
            {
                // Create design time view models
            }
            else
            {
                // Create run time view models               
            }
        }

        #region main

        private static MainViewModel _main;

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        public static MainViewModel MainStatic
        {
            get
            {
                if (_main == null)
                {
                    CreateMain();
                }

                return _main;
            }
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return MainStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the Main property.
        /// </summary>
        public static void ClearMain()
        {
            if (_main != null)
            {
                _main.Cleanup();
                _main = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the Main property.
        /// </summary>
        public static void CreateMain()
        {
            if (_main == null)
            {
                _main = new MainViewModel();
            }
        }

        #endregion

        #region game menu

        private static MenuViewModel _gameMenu;

        /// <summary>
        /// Gets the GameMenu property.
        /// </summary>
        public static MenuViewModel GameMenuStatic
        {
            get
            {
                if (_gameMenu == null)
                {
                    CreateGameMenu();
                }

                return _gameMenu;
            }
        }

        /// <summary>
        /// Gets the GameMenu property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MenuViewModel GameMenu
        {
            get
            {
                return GameMenuStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the GameMenu property.
        /// </summary>
        public static void ClearGameMenu()
        {
            if (_gameMenu != null)
            {
                _gameMenu.Cleanup();
                _gameMenu = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the GameMenu property.
        /// </summary>
        public static void CreateGameMenu()
        {
            if (_gameMenu == null)
            {
                _gameMenu = new MenuViewModel();
            }
        }

        #endregion

        #region game

        private static GameViewModel _game;

        /// <summary>
        /// Gets the Game property.
        /// </summary>
        public static GameViewModel GameStatic
        {
            get
            {
                if (_game == null)
                {
                    CreateGame();
                }

                return _game;
            }
        }

        /// <summary>
        /// Gets the Game property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public GameViewModel Game
        {
            get
            {
                return GameStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the Game property.
        /// </summary>
        public static void ClearGame()
        {
            if (_game != null)
            {
                _game.Cleanup();
                _game = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the Game property.
        /// </summary>
        public static void CreateGame()
        {
            if (_game == null)
            {
                _game = new GameViewModel();
            }
        }

        #endregion

        #region options

        private static OptionsViewModel _options;

        /// <summary>
        /// Gets the Options property.
        /// </summary>
        public static OptionsViewModel OptionsStatic
        {
            get
            {
                if (_options == null)
                {
                    CreateOptions();
                }

                return _options;
            }
        }

        /// <summary>
        /// Gets the Options property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public OptionsViewModel Options
        {
            get
            {
                return OptionsStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the Options property.
        /// </summary>
        public static void ClearOptions()
        {
            if (_options != null)
            {
                _options.Cleanup();
                _options = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the Options property.
        /// </summary>
        public static void CreateOptions()
        {
            if (_options == null)
            {
                _options = new OptionsViewModel();
            }
        }

        #endregion

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearMain();
            ClearGameMenu();
            ClearGame();
            ClearOptions();
        }
    }
}